package com.pai4j.remote.pgc;

import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.domain.vo.request.subjectaccount.CreateSubjectRequest;
import com.pai4j.domain.vo.request.subjectaccount.UpdateSubjectRequest;
import com.pai4j.domain.vo.response.subjectaccount.ArticleBaseResponseVO;
import com.pai4j.domain.vo.response.subjectaccount.SubjectBaseResponseVO;
import com.pai4j.domain.vo.response.subjectaccount.SubjectStatisticsVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(name = "pai4j-pgc-service", contextId = "subjectClient")
public interface SubjectClient {
    
    /**
     * 创建专题
     *
     * @author: CYM-pai
     * @date: 2025/05/02 10:18
     **/
    @PostMapping("/pgc-service/subject/create")
    PAIResponseBean<Boolean> create(@RequestBody CreateSubjectRequest subjectRequest);
    
    /**
     * 更新专题
     *
     * @author: CYM-pai
     * @date: 2025/05/07
     **/
    @PostMapping("/pgc-service/subject/update")
    PAIResponseBean<Boolean> update(@RequestBody UpdateSubjectRequest subjectRequest);
    
    
    /**
     * 分页查询专题
     *
     * @author: CYM-pai
     * @date: 2025/05/07 16:50
     **/
    @GetMapping("/pgc-service/subject/list")
    PAIResponseBean<PAIPageResponseBeanUtil<List<SubjectBaseResponseVO>>> getSubjectList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                 @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                 @RequestParam (value = "author", required = false) String author);
    /**
     * 获取专题基本信息
     *
     * @author: CYM-pai
     * @date: 2025/05/08 15:50
     **/
    @GetMapping("/pgc-service/subject/info/{subjectAccount}")
    PAIResponseBean<SubjectBaseResponseVO> getSubjectBaseInfo(@PathVariable ("subjectAccount")Long subjectAccount);
    
    /**
     * 获取专题id和名称集合
     *
     * @author: CYM-pai
     * @date: 2025/05/09 20:50
     **/
    @GetMapping("/pgc-service/subject/idAndName/{subjectId}")
    PAIResponseBean<Map<Long,String>> getSubjectIdAndName(@PathVariable("subjectId") Long subjectId);
    
    /**
     * 获取当前用户（作者）的专题id和名称集合
     *
     * @author: CYM-pai
     * @date: 2025/05/10 20:47
     **/
    @GetMapping("/pgc-service/subject/article/idAndName/{userId}")
    PAIResponseBean<Map<Long,String>> getSubjectIdAndName(@PathVariable("userId") String userId);
    
    
    @GetMapping("/pgc-service/subject/articleList/{subjectAccount}")
    PAIResponseBean<PAIPageResponseBeanUtil<List<ArticleBaseResponseVO>>> getSubjectArticleList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                                                @RequestParam (value = "subjectAccount", required = false) Long subjectAccount);
    
    /**
     * 订阅/关注专题
     *
     * @author: CYM-pai
     * @date: 2025/05/16 19:48
     **/
    @PostMapping("/pgc-service/subject/subscribe/{userId}/{subjectId}")
    PAIResponseBean<Boolean> subscribe(@PathVariable("userId") String userId,
                                       @PathVariable("subjectId")Long subjectId);
    
    /**
     * 取消订阅/关注专题
     *
     * @author: CYM-pai
     * @date: 2025/05/16 19:48
     **/
    @PostMapping("/pgc-service/subject/unsubscribe/{userId}/{subjectId}")
    PAIResponseBean<Boolean> unsubscribe(@PathVariable("userId")String userId,
                                         @PathVariable("subjectId") Long subjectId);
    
    /**
     *  获取专题是否被订阅/关注状态: 判断是否已订阅/关注
     *
     * @author: CYM-pai
     * @date: 2025/07/07 10:42
     **/
    @GetMapping("/pgc-service/subject/isSubscribe/{relationType}/{userId}/{subjectId}")
    PAIResponseBean<Boolean> getSubscribeStatus(@PathVariable Integer relationType,@PathVariable String userId, @PathVariable Long subjectId);
    
    
    /**
     *  获取专题推荐列表
     *
     * @author: CYM-pai
     * @date: 2025/07/08 10:13
     **/
    @GetMapping("/pgc-service/subject/recommand/{subjectId}")
    PAIResponseBean<SubjectBaseResponseVO> getSubjectRecommand(@PathVariable("subjectId") Long subjectId);

    /**
     * 获取专题统计信息（包含订阅数、文章总数、已发布文章数）
     *
     * @param subjectId 专题ID
     * @return 专题统计信息
     */
    @GetMapping("/pgc-service/subject/statistics/{subjectId}")
    PAIResponseBean<SubjectStatisticsVO> getSubjectStatistics(@PathVariable("subjectId") Long subjectId);
    
    /**
     * 删除专题（逻辑删除）
     *
     * @param subjectId 专题ID
     * @param author 作者（用于权限验证）
     * @return 是否删除成功
     */
    @DeleteMapping("/pgc-service/subject/delete")
    PAIResponseBean<Boolean> deleteSubject(
            @RequestParam("subjectId") Long subjectId,
            @RequestParam("author") String author);
    
    /**
     * 恢复已删除的专题（支持级联恢复）
     *
     * @param subjectId 专题ID
     * @param author 作者（用于权限验证）
     * @param cascadeRestore 是否级联恢复专题下的文章（true=恢复文章，false=只恢复专题）
     * @return 是否恢复成功
     */
    @PostMapping("/pgc-service/subject/restore/cascade")
    PAIResponseBean<Boolean> restoreSubjectWithCascade(
            @RequestParam("subjectId") Long subjectId,
            @RequestParam("author") String author,
            @RequestParam(value = "cascadeRestore", required = false, defaultValue = "false") Boolean cascadeRestore);
    
    /**
     * 恢复已删除的专题（兼容旧接口，默认不级联恢复）
     *
     * @param subjectId 专题ID
     * @param author 作者（用于权限验证）
     * @return 是否恢复成功
     */
    @PostMapping("/pgc-service/subject/restore")
    PAIResponseBean<Boolean> restoreSubject(
            @RequestParam("subjectId") Long subjectId,
            @RequestParam("author") String author);
    
    /**
     * 分页查询指定作者已删除的专题（回收站）
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param author 作者
     * @return 已删除专题分页列表
     */
    @GetMapping("/pgc-service/subject/deleted/author")
    PAIResponseBean<PAIPageResponseBeanUtil<List<SubjectBaseResponseVO>>> pageDeletedByAuthor(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "author") String author);
    
    /**
     * 统计指定作者的专题数量
     *
     * @param author 作者
     * @param deleteFlag 删除标识（1=未删除，0=已删除）
     * @return 专题数量
     */
    @GetMapping("/pgc-service/subject/count/author")
    PAIResponseBean<Long> countSubjectsByAuthor(
            @RequestParam("author") String author,
            @RequestParam("deleteFlag") Integer deleteFlag);
    
    /**
     * 物理删除专题（管理员专用，级联物理删除）
     *
     * @param subjectId 专题ID
     * @param adminUser 管理员用户（用于审计记录）
     * @return 是否删除成功
     */
    @DeleteMapping("/pgc-service/subject/physical/delete")
    PAIResponseBean<Boolean> physicalDeleteSubject(
            @RequestParam("subjectId") Long subjectId,
            @RequestParam("adminUser") String adminUser);
}
